package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.CartSevice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * TODO
 *
 * @Author mr.wu
 * @Data #{DATE} #{TIME}
 */
@RestController
@RequestMapping("/user/shoppingCart")
public class CartController {

    @Autowired
    private CartSevice cartSevice;

    /**
     * 添加购物车
     * @param dto
     * @return
     */
    @PostMapping("/add")
    public Result addCart(@RequestBody ShoppingCartDTO dto){
        cartSevice.add(dto);
        return Result.success();
    }

    /**
     * 查看购物车
     * @return
     */
    @GetMapping("list")
    public Result<List<ShoppingCart>> getList(){
        List<ShoppingCart> cartlist = cartSevice.getList();
        return Result.success(cartlist);
    }

    /**
     * 清空购物车
     * @return
     */
    @DeleteMapping("clean")
    public Result delete(){
         cartSevice.delete();
        return Result.success();
    }

}
